<?php
class framework_base_page
{
    /**
     * 分页类
	 *@Param:url地址,pagesize 每页显示数量,nums总数,currentPage当前页数
	 *@Param-CSS:ot 其他样式,in选中样式,fs 字体样式 , dv DIV层样式
     *@Author:lsz
     *@Time: 2013 
    **/
	public function page($url,$pagesize,$nums,$currentPage=null,$css=array()){
        $pages=ceil($nums/$pagesize);
        if($currentPage>$pages){
            $currentPage=$pages;
        }
        if($currentPage < 1){
            $currentPage=1;
        }
        $beginNum = ($currentPage-1)*$pagesize;
        $limit="$beginNum,$pagesize";
        $pre = $currentPage-1;
        if($pre<1)
        {
            $pre=1;
        }
        $next = $currentPage +1;
        if($next>$pages)
        {
            $next=$pages;
        }

        $show ="<FORM METHOD=POST ACTION={$url}><div class='".$css['dv']."'>
        总共：<b class='".$css['fs']."'>".$nums."</b>条&nbsp;页数：<b class='".$css['fs']."'>".$currentPage."/".$pages."</b>&nbsp;";

        $show.= "<a href='$url&page=1'>首页</a>&nbsp;";	

        $show.= "<a href='$url&page=$pre'>上一页</a>&nbsp;";

        for($i=1;$i<=$pages;$i++)
       {
            if($i>$currentPage+2 || $i<$currentPage-2)
                continue;
            if($i==$currentPage)
            $show.= "<a class='".$css['in']."'><b>$i</b></a>&nbsp;";
            else
            $show.= "<a href='$url&page=$i' class='".$css['ot']."'><b>$i</b></a>&nbsp;";
            }

        $show.= "<a href='$url&page=$next'>下一页</a>&nbsp;";

        $show.= "<a href='$url&page=$pages'>尾页</a>&nbsp;";
		//跳转输入框
		//$show.="<INPUT TYPE='text' NAME='postPage' size=2 value='$currentPage'><INPUT TYPE='submit' value='跳转' class='".$css['sub']."' >";
        $show.="</div></FORM>";

        $showpage['limit']=$limit;
        $showpage['show']=$show;
        return $showpage;
	}
}
